typedef struct {
	unsigned int len:7;
	unsigned int farg:1;
} __attribute__ ((__packed__)) Bit_farg;

#include "bild/svart_torn.h"
#include "bild/svart_hast.h"
#include "bild/svart_lopare.h"
#include "bild/svart_dam.h"
#include "bild/svart_kung.h"
#include "bild/svart_bonde.h"
#include "bild/vit_torn.h"
#include "bild/vit_hast.h"
#include "bild/vit_lopare.h"
#include "bild/vit_dam.h"
#include "bild/vit_kung.h"
#include "bild/vit_bonde.h"

char bildpixlar[12][60*60*4];

char* get_uncompressed_pjas( int nummer ) {
	typedef struct {
		const Bit_farg* bitar;
		const char* start_end;
		int len;
	} Bild;

	unsigned char(*pixels)[4] = (unsigned char(*)[4])bildpixlar[nummer];
	for( int i=0; i<60*60; i++ ) pixels[i][3] = 0;

	static const Bit_farg * const _bitar[12] = {svart_torn, svart_hast, svart_lopare, svart_dam, svart_kung, svart_bonde, vit_torn, vit_hast, vit_lopare, vit_dam, vit_kung, vit_bonde};
	static const char * const _start_end[12] = {svart_torn_, svart_hast_, svart_lopare_, svart_dam_, svart_kung_, svart_bonde_, vit_torn_, vit_hast_, vit_lopare_, vit_dam_, vit_kung_, vit_bonde_};
	static const int _len[12] = {svart_torn_l, svart_hast_l, svart_lopare_l, svart_dam_l, svart_kung_l, svart_bonde_l, vit_torn_l, vit_hast_l, vit_lopare_l, vit_dam_l, vit_kung_l, vit_bonde_l};

	Bild bild = {_bitar[nummer], _start_end[nummer], _len[nummer]};

	int pos = bild.start_end[0]+bild.start_end[1]*60;
	for( int i=0; i<pos; i++ ) {
		pixels[i][0] = 0;
		pixels[i][1] = 0;
		pixels[i][2] = 0xff;
	}
	char farg_innan = 2;
	for( int i=0; i<bild.len; i++ ) {
		static const char tabell[3][2] = {{1, 2}, {0, 2}, {0, 1}};
		char f = tabell[farg_innan][bild.bitar[i].farg];
		for( int j=0; j<bild.bitar[i].len; j++ ) {
			pixels[pos][0] = (f==1) ? 0xff : 0;
			pixels[pos][1] = (f==1) ? 0xff : 0;
			pixels[pos][2] = (f!=0) ? 0xff : 0;
			pos++;
		}
		farg_innan = f;
	}
	for( int i=pos; i<60*60; i++ ) {
		pixels[i][0] = 0;
		pixels[i][1] = 0;
		pixels[i][2] = 0xff;
	}
	return (char*)pixels;
}
